package com.hspedu.hspliving.commodity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hspedu.hspliving.commodity.dto.BrandDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hspedu.common.utils.PageUtils;
import com.hspedu.common.utils.Query;

import com.hspedu.hspliving.commodity.dao.BrandDao;
import com.hspedu.hspliving.commodity.entity.BrandEntity;
import com.hspedu.hspliving.commodity.service.BrandService;

@Slf4j
@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {
    @Autowired
    private BrandDao brandDao;
    @Override
    public PageInfo<BrandEntity> queryPage(BrandDTO brandDTO) {
        //开始分页
        PageHelper.startPage(brandDTO.getPageNum(),brandDTO.getPageSize());
        log.info("查询入参={}",brandDTO);
        LambdaQueryWrapper<BrandEntity> wrapper = new LambdaQueryWrapper<>();
        if (brandDTO.getName() != null && !StringUtils.isBlank(brandDTO.getName())){//带检索条件
            wrapper.like(BrandEntity::getName,brandDTO.getName());
        }
//        IPage<BrandEntity> page = brandDao.selectPage(
//                new Query<BrandEntity>().getPage(params),
//                wrapper
//        );
        List<BrandEntity> brandEntities = brandDao.selectList(wrapper);
        return new PageInfo<>(brandEntities);
    }

}
